<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use App\Model\Admin as Mod;

class gLang
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $language = session('language');
        if (empty($language)) {
            $language = session('language_id');
        }
        $language = (int) $language;
        if ($language == 1) {
            App::setLocale('en');
        } elseif ($language == 2) {
            App::setLocale('zh_tw');
        } elseif ($language == 3) {
            App::setLocale('zh');
        } else {
            $language = 3;
            App::setLocale('zh');
        }
        session(['language'=>$language]);

        return $next($request);
    }
}
